//
//  DKBaseInfoInputView.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/12.
//

#import "DKBaseInfoInputView.h"
@interface DKBaseInfoInputView()<UITextFieldDelegate>
@property (nonatomic,strong) UIView *dk_baseInfoView;
@property (nonatomic, strong)UILabel * dk_baseInfoHeadLab;
@property (nonatomic, strong)UITextField * dk_baseInfoField;
@end
@implementation DKBaseInfoInputView
-(instancetype)init{
    if(self == [super init]){
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_baseInfoHeadLab = [[UILabel alloc] init];
    self.dk_baseInfoHeadLab.textColor = DK_Hex(@"#999999");
    self.dk_baseInfoHeadLab.font = DK_FONT_Regular(14);
    [self addSubview:self.dk_baseInfoHeadLab];
    [self.dk_baseInfoHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(20)));
    }];
    self.dk_baseInfoView = [[UIView alloc] init];
    self.dk_baseInfoView.layer.cornerRadius = DK_IsWidthScale(14);
    self.dk_baseInfoView.layer.borderWidth = 0.5;
    self.dk_baseInfoView.layer.borderColor = DK_Hex(@"#4566FF").CGColor;
    self.dk_baseInfoView.backgroundColor = DK_Hex(@"#F7F7F8");
    [self addSubview:self.dk_baseInfoView];
    [self.dk_baseInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_baseInfoHeadLab.mas_bottom).offset(DK_IsWidthScale(10));
        make.bottom.equalTo(@(-DK_IsWidthScale(10)));
    }];
    self.dk_baseInfoField = [[UITextField alloc] init];
    self.dk_baseInfoField.font = DK_FONT_Medium(14);
    self.dk_baseInfoField.placeholder = @"Please select";
    self.dk_baseInfoField.delegate = self;
    [self.dk_baseInfoField addTarget:self action:@selector(fieldEditChange) forControlEvents:UIControlEventEditingChanged];
    [self.dk_baseInfoView addSubview:self.dk_baseInfoField];
    [self.dk_baseInfoField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
}
- (void)fieldEditChange{
    if(self.InputScuessBlock){
        self.InputScuessBlock();
    }
}
-(void)setAuthBaseStepInputType:(AuthBaseStepInputType)authBaseStepInputType{
    _authBaseStepInputType = authBaseStepInputType;
    switch (_authBaseStepInputType) {
        case AuthBaseStepInputTypeMonthlySalary:
            self.dk_baseInfoHeadLab.text = @"Monthly salary";
            self.dk_baseInfoField.keyboardType = UIKeyboardTypeNumberPad;
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        case AuthBaseStepInputTypeEmailAddress:
            self.dk_baseInfoHeadLab.text = @"E-mail address";
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        case AuthBaseStepInputTypeBankAccountNo:
            self.dk_baseInfoHeadLab.text = @"Bank Account No";
            self.dk_baseInfoField.placeholder = @"Please enter";
            self.dk_baseInfoField.keyboardType = UIKeyboardTypeNumberPad;
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        case AuthBaseStepInputTypeConfirmBankAccount:
            self.dk_baseInfoHeadLab.text = @"Confirm Bank Account No";
            self.dk_baseInfoField.placeholder = @"Please enter";
            self.dk_baseInfoField.keyboardType = UIKeyboardTypeNumberPad;
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        case AuthBaseStepInputTypeIFSC:
            self.dk_baseInfoHeadLab.text = @"IFSC";
            self.dk_baseInfoField.placeholder = @"Please enter";
            self.dk_baseInfoField.keyboardType = UIKeyboardTypeASCIICapable;
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        case AuthBaseStepInputTypeConfirmIFSC:
            self.dk_baseInfoHeadLab.text = @"Confirm IFSC";
            self.dk_baseInfoField.placeholder = @"Please enter";
            self.dk_baseInfoField.keyboardType = UIKeyboardTypeASCIICapable;
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        case AuthBaseStepInputTypeBank:
            self.dk_baseInfoHeadLab.text = @"Bank";
            self.dk_baseInfoField.placeholder = @"Please enter";
            self.dk_baseInfoView.layer.borderWidth = 0;
            break;
        default:
            break;
    }
}
- (void)changeErrorStepStatusInput:(BOOL)isError{
    if(isError){
        self.dk_baseInfoView.layer.borderWidth = 0.5;
        self.dk_baseInfoView.layer.borderColor = DK_Hex(@"#ED4342").CGColor;
    }else{
        self.dk_baseInfoView.layer.borderWidth = 0;
    }
}

- (NSString *)getStepStatusInput{
    return self.dk_baseInfoField.text;
}
-(void)setBankInfo:(NSString *)bankInfo{
    _bankInfo = bankInfo;
    self.dk_baseInfoField.text = _bankInfo;
}
- (void)requestUserBrhavRecord:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyBasic withAction:action complete:^{
            
    } fail:^{
            
    }];
}
- (void)requestUserBrhavRecordBankCard:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    if([self.inputStatus isEqualToString:@"1"]){
        [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyBankcard withAction:action complete:^{
                
        } fail:^{
                
        }];
    }else{
        [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_EditBankcard withAction:action complete:^{
                
        } fail:^{
                
        }];
    }
}

#pragma mark -- UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if(_authBaseStepInputType == AuthBaseStepInputTypeMonthlySalary){
        [self requestUserBrhavRecord:DK_ActionMonthly_Income_Focus withParmDic:@{}];
    }else if(_authBaseStepInputType == AuthBaseStepInputTypeEmailAddress){
        [self requestUserBrhavRecord:DK_ActionEMail_Focus withParmDic:@{}];
    }else if(_authBaseStepInputType == AuthBaseStepInputTypeBankAccountNo){
        [self requestUserBrhavRecordBankCard:DK_ActionBank_Account_Focus withParmDic:@{}];
    }else if(_authBaseStepInputType == AuthBaseStepInputTypeConfirmBankAccount){
        if(![self.inputStatus isEqualToString:@"2"]){
            [self requestUserBrhavRecordBankCard:DK_ActionBank_Account_Confirm_Focus withParmDic:@{}];
        }
    }else if(_authBaseStepInputType == AuthBaseStepInputTypeIFSC){
        [self requestUserBrhavRecordBankCard:DK_ActionIFSC_Focus withParmDic:@{}];
    }else if(_authBaseStepInputType == AuthBaseStepInputTypeConfirmIFSC){
        if(![self.inputStatus isEqualToString:@"2"]){
            [self requestUserBrhavRecordBankCard:DK_ActionIFSC_Confirm_Focus withParmDic:@{}];
        }
    }else if(_authBaseStepInputType == AuthBaseStepInputTypeBank){
        [self requestUserBrhavRecordBankCard:DK_ActionBank_Name_Focus withParmDic:@{}];
    }
}
//#pragma mark UITextFieldDelegate
//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
//    NSString * dk_baseInfoText = [textField.text stringByReplacingCharactersInRange:range withString:string];
//    if(self.InputScuessBlock){
//        self.InputScuessBlock();
//    }
//    return YES;
//}
@end
